#!/bin/bash
echo "hello"
PATH=/usr/bin:/home/pi/git/wiringPi/gpio

# Shutdown signal listen pin
gpio mode 27 in
gpio write 27 0
# Shutdown signal send pin
gpio mode 28 out
gpio write 28 1
# Amp power pin
gpio write 29 0
gpio mode 29 out

sudo sleep 1

#echo "Starting Streamer"
python /home/pi/git/sb-player/Streamer.py &

echo "Shutdown checker script starting..."
echo "Asserting pins (27=in,low; 28=out,high). Pi will shutdown when 27 goes high"

while [ 1 ]; do
    if [ "$(/home/pi/git/wiringPi/gpio/gpio read 27)" = "1" ]; then
        echo "PIN 27 requested a SYSTEM HALT !"
        sudo shutdown -h now
  break
    fi
    sudo sleep 0.5
done

exit 0
